package com.dyh.quickdemo.demos.lbdbean;

import com.alibaba.fastjson.JSON;
import com.dyh.quickdemo.bizDemo.syncWarehouseToWms.Action;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.function.Consumer;

/*
@Author=Joey Wheeler
@Date=2020/12/30 10:57
*/
@SpringBootTest
@Slf4j
public class OrderBizTest {

//    @Autowired
//    OrderBiz orderBiz;

//    @Autowired
//    Consumer<String> orderBiz$pushToWms;
//
//    @Autowired
//    Consumer<String> orderBiz$createWmsOrder;
//
//    @Autowired
//    Consumer<String> orderBiz$updateWmsOrderStatus;

//    @Autowired
//    Consumer<String> orderBiz$push;

    @Autowired
    OrderBiz orderBiz;

    @Test
    public void test(){
      //  orderBiz$push.accept("a");
        String orderId = "1";
        List<Action> actions = Macro.init("订单推送")
                .plan(
                        ()->orderBiz.createWmsOrder(orderId),
                        ()->orderBiz.pushToWms(orderId),
                        ()->orderBiz.updateWmsOrderStatus(orderId)
                )
                .run();

        System.out.println(JSON.toJSONString(actions));
        /*
        [{},{},{}]

        [{}]


        **/
    }

    /*
    2020-12-31 18:12:08.576  INFO 2920 --- [           main] c.dyh.quickdemo.demos.lbdbean.OrderBiz   : 创建wmsOrder 1
2020-12-31 18:12:08.577  INFO 2920 --- [           main] c.dyh.quickdemo.demos.lbdbean.OrderBiz   : 开始推送订单 1
2020-12-31 18:12:08.578  INFO 2920 --- [           main] c.dyh.quickdemo.demos.lbdbean.OrderBiz   : 推送订单成功 1
    */

    /*

    2020-12-31 18:09:25.466  INFO 12604 --- [           main] c.dyh.quickdemo.demos.lbdbean.OrderBiz   : 创建wmsOrder 11
2020-12-31 18:09:25.467  INFO 12604 --- [           main] c.dyh.quickdemo.demos.lbdbean.OrderBiz   : 开始推送订单 11
2020-12-31 18:09:25.467  INFO 12604 --- [           main] c.dyh.quickdemo.demos.lbdbean.OrderBiz   : 推送订单成功 11
2020-12-31 18:09:25.467  INFO 12604 --- [           main] c.dyh.quickdemo.demos.lbdbean.OrderBiz   : 更新wmsOrder状态为推送
     */

    @Test
    public void test2(){

        System.out.println();
    }

    @Test
    public void  fun(){

        CsMacro<String> macro1 = CsMacro.init("订单推送1");
        macro1.plan(
                orderBiz::createWmsOrder,
                orderBiz::pushToWms);

        CsMacro<String> macro2 = CsMacro.init("订单推送2");
        macro2.plan(
                orderBiz::createWmsOrder,
                orderBiz::pushToWms);

        /*c1 c2 不同 但执行相同*/

        Consumer c1;
        while ((c1 = macro1.consumers.poll())!=null){
            Consumer c2 = macro2.consumers.poll();
            System.out.println(c1.equals(c2));
        }

    }

    @Test
    public void fun2(){
        System.out.println();
//        Consumer<String> c1 = orderBiz::pushToWms;
//        Consumer<String> c2 = orderBiz::pushToWms;

        //System.out.println(c1.equals(c2));
//        System.out.println(
//                ((Consumer<String>)orderBiz::pushToWms)
//                        .equals((Consumer<String>)orderBiz::pushToWms)
//        );
    }

}
